package org.springsecuritylearn.repository.jvm.lession1.demo1;

/**
 * 堆空间参数测试
 * -Xmx20m -Xms5m -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseSerialGC
 */
public class Demo7 {

    public static void main(String[] args) {
        //最大内存
        System.out.print("maxMemory=");
        System.out.println(Runtime.getRuntime().maxMemory()+" bytes");
        //可用内存
        System.out.print("free mem=");
        System.out.println(Runtime.getRuntime().freeMemory()+" bytes");
        //当前总内存
        System.out.print("total mem=");
        System.out.println(Runtime.getRuntime().totalMemory()+" bytes");


        byte[] bytes=new byte[1*1024*1024];
        System.out.println("分配了1m空间给数组");
        System.out.print("maxMemory=");
        System.out.println(Runtime.getRuntime().maxMemory()+" bytes");

        System.out.print("free mem=");
        System.out.println(Runtime.getRuntime().freeMemory()+" bytes");

        System.out.print("total mem=");
        System.out.println(Runtime.getRuntime().totalMemory()+" bytes");

         bytes=new byte[4*1024*1024];
        System.out.println("分配了4m空间给数组");
        System.out.print("maxMemory=");
        System.out.println(Runtime.getRuntime().maxMemory()/(1024*1024)+" m");

        System.out.print("free mem=");
        System.out.println(Runtime.getRuntime().freeMemory()/(1024*1024)+" m");

        System.out.print("total mem=");
        System.out.println(Runtime.getRuntime().totalMemory()/(1024*1024)+" m");



    }

}
